﻿Namespace ControlLibrary
    ''' <summary>Used to handle the print settings for the standard dbiList Control.</summary>
    Public Class dbiListPrintSettings
        Private l_LandscapeRequired As Boolean

        ''' <summary>Determines if the report must be printed in landscape mode.</summary>
        ''' <remarks>In order to preserve formatting and column integrity this value
        ''' will return true if the extra width is required.</remarks>
        Public Property LandscapeRequired() As Boolean
            Get
                Return l_LandscapeRequired
            End Get
            Set(ByVal value As Boolean)
                l_LandscapeRequired = value

                If value Then
                    Me.CheckBoxPrintLandscape.Checked = True
                    Me.CheckBoxPrintLandscape.Enabled = False
                End If
            End Set
        End Property

        ''' <summary>
        ''' Loads the dbiList current settings as well as a predefined PrinterSettings.
        ''' </summary>
        ''' <param name="curList">The dbiList to get the settings from.</param>
        ''' <param name="curPrinterSettings">A system.drawing.printing.printersettings object to set defaults from.</param>
        ''' <remarks></remarks>
        Public Sub LoadSettingsFromList(ByRef curList As Dbi.WinControl.List.dbiList, ByRef curPrinterSettings As System.Drawing.Printing.PrinterSettings)

            'Sets the various controls based on the curList settings and the curPrinterSettings.
            Me.TextBoxPageTitle.Text = curList.PrintPageTitleText
            Me.TextBoxPageSubTitle.Text = curList.PrintPageSubTitleText

            Me.CheckBoxPrintPageSubTitle.Checked = curList.PrintPageSubTitle
            Me.CheckBoxPrintPageTitle.Checked = curList.PrintPageTitle

            Me.ButtonPrintHeaderBackColor.BackColor = curList.PrintHeaderBackColor
            Me.ButtonPrintHeaderForeColor.BackColor = curList.PrintHeaderForeColor

            Me.ButtonPrintItemBackColor.BackColor = curList.PrintItemBackColor
            Me.ButtonPrintItemForeColor.BackColor = curList.PrintItemForeColor

            Me.ButtonPrintTitleBackColor.BackColor = curList.PrintTitleBackColor
            Me.ButtonPrintTitleForeColor.BackColor = curList.PrintTitleForeColor

            Me.DbiLabelPageFooterFont.Font = curList.PrintPageFooterFont
            Me.DbiLabelSubTitleFont.Font = curList.PrintPageSubTitleFont
            Me.DbiLabelTitleFont.Font = curList.PrintPageTitleFont

            Me.CheckBoxPrintPageControl.Checked = Not (curList.PrintPageControl)
            Me.CheckBoxPrintPAgeFooter.Checked = curList.PrintPageFooter
            Me.CheckBoxPrintLandscape.Checked = curPrinterSettings.DefaultPageSettings.Landscape
            Me.CheckBoxPrintColor.Checked = curPrinterSettings.DefaultPageSettings.Color

            Me.ComboBoxPrintListFormat.DataSource = System.Enum.GetValues(GetType(Dbi.WinControl.enumPrintListFormat))
            Me.ComboBoxPrintListFormat.SelectedItem = curList.PrintListFormat

            Me.ComboBoxPrintPageBorder.DataSource = System.Enum.GetValues(GetType(Dbi.enumBorderType))
            Me.ComboBoxPrintPageBorder.SelectedItem = curList.PrintPageBorder

            Me.ComboBoxPageFooterAlign.DataSource = System.Enum.GetValues(GetType(System.Drawing.ContentAlignment))
            Me.ComboBoxPageFooterAlign.SelectedItem = curList.PrintPageFooterAlign

            Me.ComboBoxPageTitleAlign.DataSource = System.Enum.GetValues(GetType(System.Drawing.ContentAlignment))
            Me.ComboBoxPageTitleAlign.SelectedItem = curList.PrintPageTitleAlign

            Me.ComboBoxPageSubTitleAlign.DataSource = System.Enum.GetValues(GetType(System.Drawing.ContentAlignment))
            Me.ComboBoxPageSubTitleAlign.SelectedItem = curList.PrintPageSubTitleAlign

            Me.ComboBoxReportType.DataSource = System.Enum.GetValues(GetType(Dbi.WinControl.enumPrintReportType))
            Me.ComboBoxReportType.SelectedItem = curList.PrintReportType

            Me.NumericUpDownMarginBottom.Value = curPrinterSettings.DefaultPageSettings.Margins.Bottom
            Me.NumericUpDownMarginLeft.Value = curPrinterSettings.DefaultPageSettings.Margins.Left
            Me.NumericUpDownMarginRight.Value = curPrinterSettings.DefaultPageSettings.Margins.Right
            Me.NumericUpDownMarginTop.Value = curPrinterSettings.DefaultPageSettings.Margins.Top



            Me.Refresh()


        End Sub

        ''' <summary>
        ''' Sets the dbiList and PrinterSettings object with the values set in the control.
        ''' </summary>
        ''' <param name="curList">The dbiList to apply the values set herein.</param>
        ''' <param name="curPrinterSettings">The system.drawing.printing.printersettings object to apply the values set herein.</param>
        Public Sub ApplySettingsToList(ByRef curList As Dbi.WinControl.List.dbiList, ByRef curPrinterSettings As System.Drawing.Printing.PrinterSettings)
            curList.PrintPageTitleText = Me.TextBoxPageTitle.Text
            curList.PrintPageSubTitleText = Me.TextBoxPageSubTitle.Text

            curList.PrintPageTitle = Me.CheckBoxPrintPageTitle.Checked
            curList.PrintPageSubTitle = Me.CheckBoxPrintPageSubTitle.Checked

            curList.PrintHeaderBackColor = Me.ButtonPrintHeaderBackColor.BackColor
            curList.PrintHeaderForeColor = Me.ButtonPrintHeaderForeColor.BackColor

            curList.PrintItemBackColor = Me.ButtonPrintItemBackColor.BackColor
            curList.PrintItemForeColor = Me.ButtonPrintItemForeColor.BackColor

            curList.PrintTitleBackColor = Me.ButtonPrintTitleBackColor.BackColor
            curList.PrintTitleForeColor = Me.ButtonPrintTitleForeColor.BackColor

            curList.PrintPageFooterFont = Me.DbiLabelPageFooterFont.Font
            curList.PrintPageSubTitleFont = Me.DbiLabelSubTitleFont.Font
            curList.PrintPageTitleFont = Me.DbiLabelTitleFont.Font

            curList.PrintPageControl = Not (Me.CheckBoxPrintPageControl.Checked)
            curList.PrintPageFooter = Me.CheckBoxPrintPAgeFooter.Checked
            curPrinterSettings.DefaultPageSettings.Landscape = Me.CheckBoxPrintLandscape.Checked
            curPrinterSettings.DefaultPageSettings.Color = Me.CheckBoxPrintColor.Checked

            curList.PrintListFormat = Me.ComboBoxPrintListFormat.SelectedItem
            curList.PrintPageBorder = Me.ComboBoxPrintPageBorder.SelectedItem
            curList.PrintPageFooterAlign = Me.ComboBoxPageFooterAlign.SelectedItem
            curList.PrintPageTitleAlign = Me.ComboBoxPageTitleAlign.SelectedItem
            curList.PrintPageSubTitleAlign = Me.ComboBoxPageSubTitleAlign.SelectedItem

            curPrinterSettings.DefaultPageSettings.Margins.Bottom = Me.NumericUpDownMarginBottom.Value
            curPrinterSettings.DefaultPageSettings.Margins.Left = Me.NumericUpDownMarginLeft.Value
            curPrinterSettings.DefaultPageSettings.Margins.Right = Me.NumericUpDownMarginRight.Value
            curPrinterSettings.DefaultPageSettings.Margins.Top = Me.NumericUpDownMarginTop.Value

            curList.PrintReportType = Me.ComboBoxReportType.SelectedItem
        End Sub

        ''' <summary>Displays a color dialog if the color button is clicked.</summary>
        Private Sub ButtonColor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPrintItemForeColor.Click, ButtonPrintItemBackColor.Click, ButtonPrintHeaderForeColor.Click, ButtonPrintHeaderBackColor.Click, ButtonPrintTitleForeColor.Click, ButtonPrintTitleBackColor.Click
            ColorDialog1.Color = sender.backcolor
            ColorDialog1.ShowDialog()
            sender.backcolor = ColorDialog1.Color
        End Sub

        ''' <summary>Displays a font dialog if the font label is clicked.</summary>
        Private Sub FontLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DbiLabelTitleFont.Click, DbiLabelSubTitleFont.Click, DbiLabelPageFooterFont.Click
            FontDialog1.Font = sender.font
            FontDialog1.ShowDialog()
            sender.font = FontDialog1.Font
        End Sub
    End Class
End Namespace